package com.sanyou.registry;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @Author yongxin
 * @Description 实现与注册逻辑
 */
@Component
public class ServiceRegistry {

    @PostConstruct
    void initRegistry() {
        // 注册自定义函数
        LogParseFunctionFactory.registerFunction("parseContent", (params) -> {
            int productState = Optional.ofNullable(params[0]).map(Integer::parseInt).orElse(-1);
            int maintainType = Optional.ofNullable(params[1]).map(Integer::parseInt).orElse(-1);

            switch(productState) {
                case 0:
                    return "当前阴极板为:在线状态";
                case 1: {
                    String maintainTypeName = "";
                    switch (maintainType){
                        case 1: {
                            maintainTypeName = "槽面换板";
                            break;
                        }
                        case 2: {
                            maintainTypeName = "烧板";
                            break;
                        }
                        case 3: {
                            maintainTypeName = "镀铜层脱落";
                            break;
                        }
                        case 4: {
                            maintainTypeName = "弹性板";
                            break;
                        }
                    }
                    return "当前阴极板为:维修状态，维修类型为:" + maintainTypeName;
                }
                case 2:
                    return "当前阴极板为:备用状态";
                case 3:
                    return "当前阴极板为:报废状态";
            }
            return "";
        });
    }
}
